package com.leetcode.p0;

import java.util.HashSet;
import java.util.Set;

public class Test3 {

    public int lengthOfLongestSubstring(String s) {
        int right = -1;
        int maxCount = 0;

        Set<Character> set = new HashSet<>();

        for (int i = 0; i < s.length(); i++) {
            if (i != 0) {
                set.remove(s.charAt(i - 1));
            }

            while (right + 1 < s.length() && !set.contains(s.charAt(right + 1))) {
                set.add(s.charAt(right + 1));
                right++;
            }

            maxCount = Math.max(maxCount, right - i + 1);
        }
        return maxCount;
    }


    public static void main(String[] args) {
        Test3 test = new Test3();
//        int result = test.lengthOfLongestSubstring("abcabcbb");
        int result = test.lengthOfLongestSubstring("pwwkew");
        System.out.println(result);
    }

}
